import { ElLoading, ElMessage, ElMessageBox } from 'element-plus';

export function input({ content = '请输入内容', title = '提示', value = '' }) {
  return new Promise((resolve, reject) => {
    ElMessageBox.prompt(content, title, {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      inputValue: value,
    })
      .then(({ value }) => {
        resolve(value);
      })
      .catch((error) => {
        reject(error);
      });
  });
}
export function confirm(title) {
  return new Promise((resolve, reject) => {
    ElMessageBox.confirm(title || '是否确认操作?', '操作确认', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(() => {
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
}
export function success(message) {
  ElMessage({
    message: message || '操作成功',
    type: 'success',
  });
}

export function error(message) {
  ElMessage({
    message: message || '操作失败',
    type: 'error',
  });
}

export function warning(message) {
  ElMessage({
    message: message || '警告',
    type: 'warning',
  });
}

export function alert(message) {
  ElMessageBox.alert(message || 'This is a message', 'Title', {
    confirmButtonText: '确认',
  });
}
export function openLoading() {
  return ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(0, 0, 0, 0.1)',
  })
}
export function closeLoading(loading) {
  loading.close()
}